<?php
html::printPath(
		array('orgSeminar.form-title' => '/org/orgSeminar/all', $seminar['name'] => '/org/orgSeminar/display?id=' . $seminar['id'], 'orgSeminar.registrationList' => ''),
		'orgSeminar.registrationList-desc'
);
$msg->printMessages();

echo '<ul class="commandList">';
echo '<li class="exportToExcel">' . html::anchor('/org/orgSeminar/registrationExcelExport?id=' . $seminar['id'], text::get('application-exportToExcel')) . '</li>';
echo '</ul>';

if ($paymentAcceptance['confirmed_at']) {
	echo '<p class="warningNote">' . text::getEscaped('orgSeminar-paymentAcceptanceLocked') . '</p>';
}

echo '<h3>' . text::getEscaped('orgSeminar.billing') . '</h3>';
echo '<p class="description">' . text::getEscaped('orgSeminar-billing-info', count($registrationList)) . '</p>';
echo html::displayTable(array(
		text::get('orgSeminar-billing-total') => registrationHelper::formatPrices($totalPriceByCurrency),
		text::get('orgSeminar-billing-cancellationFees') => registrationHelper::formatPrices($cancellationFeesByCurrency),
		text::get('orgSeminar.billing-cashTotal') => registrationHelper::formatPrices($totalCashPriceByCurrency),
		text::get('orgSeminar.billing-bankTotal') => registrationHelper::formatPrices($totalBankPriceByCurrency)
), false);

echo '<h2>' . text::getEscaped('orgSeminar-registrationList') . '</h2>';

echo '<h3>' . text::getEscaped('orgSeminar-validRegistrationList') . ' (' . count($registrationList) . ')</h3>';
echo '<p class="description">' . text::getEscaped('orgSeminar-validRegistrationList-info') . '</p>';

$elb = new EntityListBuilder('registration', $registrationList);
$elb->setUuid($this->REGISTRATION_LIST_UUID);
$elb->integer('id')->linkWithValue('/org/orgRegistration/display?id=', 'id')->openInPopup();
$elb->text('person_id')->doubleValue('last_name', 'first_name')->alignLeft()->orderByField('last_name')->linkWithValue('/org/orgSpace/personDisplay?id=', 'person_id');
$elb->timestamp('created_at');
$elb->text('payment_type')->l10n('registration.paymentType-short-');
$elb->price('total_price', 'currency_code')->alignRight();
$elb->price('price_paid', 'currency_code')->valueFunction('registrationHelper::pricePaidValue')->alignRight();
$elb->timestamp('confirmed_at')->valueFunction('confirmedAtValue', $paymentAcceptance);
$elb->text('confirmed_by_last_name')->labelKey('registration.confirmed_by_id')->doubleValue('confirmed_by_first_name', 'confirmed_by_last_name');
$elb->longText('org_notes')->valueFunction('orgNotesValue', $paymentAcceptance)->labelKey('yourNotes');

if ($registrationList) {
	echo '<div class="registrationList-valid">';
	$elb->write();
	echo '</div>';
}

echo '<h3>' . text::getEscaped('orgSeminar-unconfirmedRegistrationList') . ' (' . count($unconfirmedRegistrationList) . ')</h3>';
echo '<p class="description">' . text::getEscaped('orgSeminar-unconfirmedRegistrationList-info') . '</p>';
if ($unconfirmedRegistrationList) {
	$elb->setEntityList($unconfirmedRegistrationList);
	$elb->setUuid($this->UNCONFIRMED_REGISTRATION_LIST_UUID);
	echo '<div class="registrationList-unconfirmed">';
	$elb->write();
	echo '</div>';
}

echo '<h3>' . text::getEscaped('orgSeminar.cancelledRegistrationList') . ' (' . count($cancelledRegistrationList) . ')</h3>';
echo '<p class="description">' . text::getEscaped('orgSeminar-cancelledRegistrationList-info') . '</p>';

if ($cancelledRegistrationList) {
	echo '<div class="registrationList-cancelled">';
	
	$elb = new EntityListBuilder('registration', $cancelledRegistrationList);
	$elb->setUuid($this->CANCELLED_REGISTRATION_LIST_UUID);
	$elb->integer('id')->linkWithValue('/org/orgRegistration/display?id=', 'id')->openInPopup();
	$elb->text('person_id')->doubleValue('last_name', 'first_name')->alignLeft()->orderByField('last_name')->linkWithValue('/org/orgSpace/personDisplay?id=', 'person_id');
	$elb->timestamp('created_at');
	$elb->text('payment_type')->l10n('registration.paymentType-short-');
	$elb->price('total_price', 'currency_code')->alignRight();
	$elb->price('price_paid', 'currency_code')->valueFunction('registrationHelper::pricePaidValue')->alignRight();
	$elb->longText('org_notes')->valueFunction('orgNotesValue')->labelKey('yourNotes', $paymentAcceptance);
	$elb->timestamp('cancelled_at');
	$elb->text('cancelled_by_id')->doubleValue('cancelled_by_last_name', 'cancelled_by_first_name')->alignLeft()->orderByField('cancelled_by_last_name')->linkWithValue('/org/orgSpace/personDisplay?id=', 'cancelled_by_id');
	$elb->price('cancellation_fee', 'currency_code')->alignRight();
	$elb->longText('cancellation_reason');
	$elb->write();
	
	echo '</div>';
}

function orgNotesValue($registration, $entityListField, $paymentAcceptance) {
	$value = $registration['org_notes'];
	if ($value) {
		$text = '<span class="description">' . $entityListField->fieldValue($registration) . '</span> ';
		$link = text::get('common-operation-edit');
	}
	else {
		$link = text::get('common-operation-add');
	}
	
	if ($paymentAcceptance['confirmed_at']) {
		return $text;
	}
	
	return $text . html::popupForm('/org/orgRegistration/orgNotesForm?id=' . $registration['id'],
			$link,
			array(
				'title' => text::get('registration-addOrgNotes-hint'),
				'class' => 'commandInTable'
			)
	);
}

function confirmedAtValue($registration, $entityListField, $paymentAcceptance) {
	$value = $registration['confirmed_at'];
	if (! $value && ! $paymentAcceptance['confirmed_at']) {
		return html::anchor('/org/orgRegistration/confirm?id=' . $registration['id'],
				text::get('registration.confirm'),
				array(
					'title' => text::get('registration.confirm-hint'),
					'class' => 'commandInTable'
				)
		);
	}
	return $entityListField->fieldValue($registration);
}
